package com.example.as;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.sql.SQLOutput;
import java.util.List;
import java.util.Map;


public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {

    private View view;
    private Context context;
    private List<Map<String,Object>> data;
    int [] image;
    private Class[] jumpActivity={LuerActivity.class,yiziActivity.class};
    private int i=0;

    //构造
    public MyAdapter(List<Map<String, Object>> data, Context context,int[] image){

        this.data=data;
        this.context=context;
        this.image= image;
    }
    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {


        view= LayoutInflater.from(context).inflate(R.layout.item,parent,false);
        MyViewHolder myViewHolder=new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {

        int i = holder.getAdapterPosition();
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context,jumpActivity[i]);
                context.startActivity(intent);
            }
        });
        holder.card_image.setImageResource(image[position]);
        holder.textView1.setText(data.get(position).get("姓名").toString());
        holder.textView2.setText(data.get(position).get("身高").toString());
        holder.textView3.setText(data.get(position).get("性格").toString());

    }

    @Override
    public int getItemCount() {
        return data.size();

    }

    public class MyViewHolder extends RecyclerView.ViewHolder {


        ImageView card_image;
        TextView textView1,textView2,textView3;
        @SuppressLint("ResourceType")
        public MyViewHolder(@NonNull View itemView) {

            super(itemView);

            card_image=itemView.findViewById(R.id.card_image);
            textView1=itemView.findViewById(R.id.textView1);
            textView2=itemView.findViewById(R.id.textView2);
            textView3=itemView.findViewById(R.id.textView3);
        }
    }
}


